/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#ifndef SBJ_TimeInvoker_h
#define SBJ_TimeInvoker_h

#include "SBJ/Interfaces/IExceptionObserver.h"

#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>

namespace SBJ
{

/*
Class: TimeInvoker

Create TimeInvoker::Entry subclasses and give instance to the 
TimeInvoker to have their execute method called after the 
specified interval. If execute returns true, they will be fired again.
*/

class TimeInvoker : private boost::noncopyable
{
public:
	class Pimpl;

	class Entry
	{
	public:
		Entry( double intervalSecs ) : m_intervalSecs( intervalSecs ) {}

	protected:
		virtual ~Entry( void ) {}

		double getInterval( void ) const { return m_intervalSecs; }

		void setInterval( double intervalSecs ) { m_intervalSecs = intervalSecs; }

	private:
		friend class Pimpl;

		virtual bool execute( void ) = 0;

		double m_intervalSecs;
	};

	TimeInvoker( void );

	~TimeInvoker( void );

	void start( void );

	void join( void );

	void stop( bool join = true );

	void addEntry( Entry* entry );

	void cancelEntry( Entry* entry );

private:
	boost::scoped_ptr< Pimpl > m_pimpl;
};

}

#endif